package com.sannuo.system.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sannuo.common.domain.MedicalReport;
import com.sannuo.common.domain.Menu;
import com.sannuo.common.result.Result;
import com.sannuo.common.result.ResultCode;
import com.sannuo.system.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RequestMapping(value = "/Menu")
@RestController
@Api(tags = "Menu" ,description = "赵心涛")
@CrossOrigin
public class MenuController {

    @Autowired
    private MenuService menuService;


    @RequestMapping(value = "list",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有菜单信息",notes = "查询所有菜单信息",httpMethod = "GET")
    public Result menuService(Integer page, Integer limit, String searchParams) throws Exception {
        Page page1 = PageHelper.startPage(page,limit);
        List<Menu> users = menuService.selectMenu();
        System.out.println(users);
        PageInfo pageInfo = new PageInfo<>(users);
        return Result.ok(ResultCode.SUCCESS,pageInfo.getTotal(),users);
    }

    @RequestMapping(value = "update", method=RequestMethod.POST)
    @ApiOperation(value = "修改Menu",notes = "修改",httpMethod = "POST")
    public Result menuUpdate(Menu menu) throws Exception{

        int i = menuService.updateMenu(menu);
        return Result.ok(ResultCode.SUCCESS,i);

    }

    @RequestMapping(value = "add",method = RequestMethod.POST)
    @ApiOperation(value = "添加add",notes = "添加", httpMethod = "POST" )
    public Result AddMenu(Menu menu) throws Exception{
        System.out.println("menu"+menu);
        int i =menuService.addMenu(menu);
        return Result.ok(ResultCode.SUCCESS,i);
    }

    @RequestMapping(value = "{id}" , method = RequestMethod.POST)
    @ApiOperation(value = "删除",notes = "删除", httpMethod = "POST" )
    public Result DeleteMenu(@PathVariable("id") int id) throws Exception{
        int i=menuService.deleteMenu(id);
        return Result.ok(ResultCode.SUCCESS,i);
    }


}
